<template>
	<om-addpage :menuName="menuName" :busCode="busCode" @formSubmit="formSubmit" :showHistoryBtn="false">
		<view v-show="false">
			<input v-model="formdata.formId" name="formId" />
		</view>
		<uni-list title="公积金信息">
			<uni-list-item  :showArrow="false">
				<view class="tui-flex">
					<view class="tui-col-7"><om-label label="生效月份"  required></om-label></view>
					<view class="tui-left  tui-col-8">
						<picker mode="date"
							@change="bindDateChange" 
							:fields="'month'" 
							name="effectMonth" 
							v-model="formdata.effectMonth"
							:value="formdata.effectMonth"
							:end="maxMonth"
							:start="minMonth"
							>
							<view>{{formdata.effectMonth.trim()?formdata.effectMonth:"请选择"}}</view>
						</picker>
					</view>
				</view>
			</uni-list-item>
		</uni-list>
	</om-addpage>
</template>

<script>
import moment from '@/static/js/moment.js'
import dateTimePicker from '@/static/js/dateTimePicker.js';
import { ignoreHtml } from '@/static/js/common.js';
export default {
	provide() {
		return {
			formPage: this
		};
	},
	data() {
		return {
			formdata: {
				effectMonth: dateTimePicker.getNewMonth(),
				formId:""
			},
			maxMonth:"",
			minMonth:"",
			menuName: '',
			busCode: '',
			ztime:""
		};
	},
	methods: {
		getEffectMonthList(){
			let _that = this
			_that.om.request(
				"thousingFund/getEffectMonthList",
				{
					ztime:_that.ztime
				}
			).then(res=>{
				if(res.length){
					_that.minMonth= res[0].value
					_that.maxMonth =res[res.length-1].value
				}else{
					_that.maxMonth = moment().add(2,'months').format('YYYY-MM')
					_that.minMonth = moment().subtract(2,'months').format('YYYY-MM')
				}
			})
		},
		/**
		 * 生效日期
		 */
		bindDateChange(e) {
			this.formdata.effectMonth = e.detail.value;
		},
		formSubmit: function(formdata) {
			let _that = this;
			if(!formdata || Object.keys(formdata).length==0){
				formdata = _that.formdata
			}
			if(!formdata.formId ){
				_that.om.toast('没有找到对应表单标识');
				return;
			}
			if (!formdata.effectMonth) {
				_that.om.toast('请选择生效日期');
				return;
			}
			_that.om.request(
				'thousingFund/updateData',
				{
					id:_that.formdata.formId,
					effectMonth:_that.formdata.effectMonth
				},
				'post'
			).then(res=>{
					_that.om.getFormInfo(_that.formdata.formId, _that.busCode, true)
			})
		},
	},
	onLoad: function(options) {
		let _that = this;
		_that.menuName = options.title || '公积金';
		uni.setNavigationBarTitle({
			title: _that.menuName
		});
		if(options.code){
			_that.busCode = options.code
		}else{
			_that.om.toast("没有表单编码")
		}
		if(options.fileId){
			_that.formdata.formId = options.fileId
		}else{
			_that.om.toast("没有表单ID")
		}
		_that.getEffectMonthList()
	}
};
</script>

<style></style>
